﻿module Translate

//open Tokens
//open Grammar
open Microsoft.FSharp.Reflection

let toGrammarToken= 
    let targetUCIs = 
        FSharpType.GetUnionCases(typeof<Grammar.token>) 
        |> Array.map (fun uci -> (uci.Name,  FSharpValue.PreComputeUnionConstructor(uci)) ) 
        |> dict
    
    assert (FSharpType.GetUnionCases(typeof<Tokens.token>) |> Array.forall (fun uci -> targetUCIs.ContainsKey(uci.Name) && true (*number of arguments is equal *)) )
    fun (t:Tokens.token) ->
      let uci,values = FSharpValue.GetUnionFields(t,typeof<Tokens.token>)
      let caseCtor = targetUCIs.[uci.Name]
      (caseCtor values):?>Grammar.token
    
    
    